﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using dTools;
using dTools.Extensions;
namespace Demo.PTGUI
{
    public partial class FrmSetting : Form
    {
        public FrmSetting()
        {
            InitializeComponent();
            this.FixedSingle();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void FrmSetting_Load(object sender, EventArgs e)
        {
            var config = EasyConf.Read<Config>();
            txtSaveImagePath.Text = config.SaveImagePath;
            txtPTGuiPath.Text = config.PTGuiPath;
            txtSingleBackImagePath.Text = config.SingleBackImagePath;
            numberDiffSec.Value = config.DiffSec;
            txtMonitorImagePath.Text = config.MonitorImagePath;
            this.TopMost = true;
        }

        private void btnPTGuiPath_Click(object sender, EventArgs e)
        {
            Ookii.Dialogs.VistaOpenFileDialog vistaOpenFileDialog = new Ookii.Dialogs.VistaOpenFileDialog();
            if (Directory.Exists(@"C:\Program Files\PTGui"))
            {
                vistaOpenFileDialog.InitialDirectory = @"C:\Program Files\PTGui";
            }
            vistaOpenFileDialog.Multiselect = false;
            vistaOpenFileDialog.Filter = "可执行程序(PTGui.exe)|*.exe";
            if (vistaOpenFileDialog.ShowDialog() == DialogResult.OK)
            {

                txtPTGuiPath.Text = vistaOpenFileDialog.FileName;
            }
        }

        private void btnMonitorImagePath_Click(object sender, EventArgs e)
        {
            Ookii.Dialogs.VistaFolderBrowserDialog folderBrowser = new Ookii.Dialogs.VistaFolderBrowserDialog();
            folderBrowser.RootFolder = Environment.SpecialFolder.DesktopDirectory;
            folderBrowser.Description = "请选择";
            if (folderBrowser.ShowDialog() == DialogResult.OK)
                txtMonitorImagePath.Text = folderBrowser.SelectedPath;
        }

        private void btnSingleBackImagePath_Click(object sender, EventArgs e)
        {
            Ookii.Dialogs.VistaFolderBrowserDialog folderBrowser = new Ookii.Dialogs.VistaFolderBrowserDialog();
            folderBrowser.RootFolder = Environment.SpecialFolder.DesktopDirectory;
            folderBrowser.Description = "请选择";
            if (folderBrowser.ShowDialog() == DialogResult.OK)
                txtSingleBackImagePath.Text = folderBrowser.SelectedPath;
        }

        private void btnSaveImagePath_Click(object sender, EventArgs e)
        {
            Ookii.Dialogs.VistaFolderBrowserDialog folderBrowser = new Ookii.Dialogs.VistaFolderBrowserDialog();
            folderBrowser.RootFolder = Environment.SpecialFolder.DesktopDirectory;
            folderBrowser.Description = "请选择";
            if (folderBrowser.ShowDialog() == DialogResult.OK)
                txtSaveImagePath.Text = folderBrowser.SelectedPath;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!txtPTGuiPath.Text.Contains("PTGui.exe"))
            {
                MessageBox.Show("PTGUI路径错误");
                return;
            }
            if (txtSingleBackImagePath.Text==txtMonitorImagePath.Text)
            {
                MessageBox.Show("备份路径不能和监控路径一致,否则造成死循环");
                return;
            }
            EasyConf.Write(new Config
            {
                DiffSec = numberDiffSec.Value.ToInt(),
                MonitorImagePath = txtMonitorImagePath.Text,
                PTGuiPath = txtPTGuiPath.Text,
                SaveImagePath = txtSaveImagePath.Text,
                SingleBackImagePath = txtSingleBackImagePath.Text
            });
            MessageBox.Show("【保存成功实时成效】");
            this.Close();
        }

        private void bntClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
